﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using Copad.BusinessCard.Model;
using Copad.BusinessCard.BLL;

public partial class BackgroundManage_Top : BusinessCardPageBase
{
    const string LI = "<li><a  class=\"tabs6_a\" target=\"frmLeft\" onFocus=\"this.blur()\" id=\"Nav{0}\"  onclick=\"return setTab('Nav',{1});\" href=\"#\"><span>{2}</span></a></li>";
    const string SCRIPT_HEAD = "NavMenu.mTitles[{0}] = [{1}];";
    const string SCRIPT_LINE = "{{\"title\":\"{0}\" ,\"href\":\"{1}\",\"text\":\"{2}\"}},";
    //static UserBLL bll = new UserBLL();
    //static List<Functions> functions = new List<Functions>();

    protected void Page_Load(object sender, EventArgs e)
    {
        UserInfo user = Manager.CurrentUser;
        //ulong roleIDS = user.RolesIds;
        this.labUsername.Text = user.User.Username;
        //this.lblRole.Text = user.RoleName;
        //this.lblLoginCount.Text = (user.LoginCount).ToString();
        BuildMenu(user.User.ID);

    }

    private void BuildMenu(long uid)
    {
        string html = "";
        string scriptLine = "";
        string script = "";

        //UserSession user = this.Session["userInfo"] as UserSession;
        //if (user != null)
        //{
        //获取用户可用的模块列表
        //List<Function> functions = UserBLL.GetFunctions(user);
        List<Models> firstDirectorylist = ModelsBLL.GetFirstDirectory(Manager.CurrentUser, 0);
        for (int i = 0; i < firstDirectorylist.Count; i++)
        {
            html += string.Format(LI, i, i, firstDirectorylist[i].ModelName);
            scriptLine = "";
            List<Models> secondDirectorylist = ModelsBLL.GetFirstDirectory(Manager.CurrentUser, firstDirectorylist[i].ID);
            string text = "";
            foreach (Models models in secondDirectorylist)
            {
                if (models.TagData != null)
                {
                    if (models.ModelName.Length > 8)
                    {
                        text = models.ModelName.Substring(0, 8) + "(" + models.TagData + ")";
                    }
                    else
                    {
                        text = models.ModelName + "(" + models.TagData + ")";
                    }
                }
                else
                {
                    text = models.ModelName;
                }
                scriptLine += string.Format(SCRIPT_LINE, models.ModelName, models.PageDirection, text);
            }

            if (scriptLine != "" && scriptLine[scriptLine.Length - 1] == ',')
            {
                scriptLine = scriptLine.Remove(scriptLine.Length - 1);
            }
            script += string.Format(SCRIPT_HEAD, i, scriptLine);
        }


        //for (int i = 0; i < functions.Count; i++)
        //{
        //    html += string.Format(LI, i + 1, i + 1, functions[i].Name);
        //    //List<Models> models = UserBLL.GetModels(user, functions[i]);
        //    scriptLine = "";
        //    for (int j = 0; j < functions[i].ModelList.Count; j++)
        //    {
        //        scriptLine += string.Format(SCRIPT_LINE, functions[i].ModelList[j].ModelName, functions[i].ModelList[j].PageDirection);
        //    }

        //    if (scriptLine[scriptLine.Length - 1] == ',')
        //    {
        //        scriptLine = scriptLine.Remove(scriptLine.Length - 1);
        //    }
        //    script += string.Format(SCRIPT_HEAD, i + 1, scriptLine);
        //}

        //this.labFunction.Text = html;
        this.tabs.InnerHtml = "<ul id='uls'>" + html + "</ul>";
        //            this.ClientScript.RegisterClientScriptBlock(typeof(string), "menu", script, true);

        this.labScript.Text = "<script language=\"javascript\" type='text/javascript'>" + script + "</script>";
        //}        
    }

}